/**
 * @file: vscode
 * @author: v_xieyejiang
 * @Date: 2018-12-10 11:25:38
 * @Last Modified by: v_xieyejiang
 * @Last Modified time: 2019-01-10 20:52:48
 */

import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const router = new Router({
    // express 配置 https://github.com/bripkens/connect-history-api-fallback
    mode: 'history', // history hash
    routes: [
        {
            path: '*',
            redirect: '/'
        },
        {
            path: '/',
            redirect: '/hello'
        },
        {
            path: '/home',
            component: () => import('@/views/home')
        },
        {
            path: '/login',
            component: () => import('@/views/login')
        },
        {
            path: '/online',
            component: () => import('@/views/online')
        },
        {
            path: '/hello',
            name: 'hello',
            component: () => import('@/views/hello'),
            redirect: '/hello/tasks',
            children: [
                {
                    path: '/hello/tasks',
                    component: () => import('@/views/hello/tasks')
                },
                {
                    path: '/hello/trend',
                    component: () => import('@/views/hello/trend')
                },
                {
                    path: '/hello/back',
                    component: () => import('@/views/hello/back')
                }
            ]
        }
    ]
});

/**
 * 全局钩子
 *
 * @param {Object} to 目标路由
 * @param {Object} from 当前路由
 * @param {Function} from 回调函数
 */
router.beforeEach((to, from, next) => {
    next();
});

export default router;
